package com.webridge.plm.mvc;

import wt.fc.ReferenceFactory;
import wt.part.WTPart;
import wt.util.WTException;

import com.ptc.jca.mvc.components.JcaColumnConfig;
import com.ptc.mvc.components.AbstractComponentBuilder;
import com.ptc.mvc.components.ColumnConfig;
import com.ptc.mvc.components.ComponentBuilder;
import com.ptc.mvc.components.ComponentConfig;
import com.ptc.mvc.components.ComponentConfigFactory;
import com.ptc.mvc.components.ComponentParams;
import com.ptc.mvc.components.TreeConfig;

@ComponentBuilder("com.webridge.plm.mvc.EBOMTreeBuilder")
public class EBOMTreeBuilder extends AbstractComponentBuilder{
    private static final String NUMBER = "number";
    private static final String TYPE_ICON = "type_icon";
    private static final String NON_SELECTABLE_COLUMN = "non_selectable_column";
	@Override
    public Object buildComponentData(ComponentConfig config, ComponentParams params)
		throws WTException {
	    String oid = params.getParameter("oid").toString();
	    ReferenceFactory rf = new ReferenceFactory();
	    WTPart part = (WTPart) rf.getReference(oid).getObject();
	    
	    return new EBOMTreeHandler(part);
   }
    @Override
    public ComponentConfig buildComponentConfig(ComponentParams params)
		throws WTException {
	
    	ComponentConfigFactory factory=getComponentConfigFactory();
    	TreeConfig tree=factory.newTreeConfig();
    	tree.setLabel("Tree Label");
    	tree.setSelectable(true);
    	//tree.setActionModel("CustEx_tree_toolbar");
    	//a column that is suppose to hold a boolean 
    	ColumnConfig  non_selectable_column = factory.newColumnConfig (NON_SELECTABLE_COLUMN,  false);
    	non_selectable_column.setNeed(NON_SELECTABLE_COLUMN);
    	((JcaColumnConfig)non_selectable_column).setDataUtilityId(NON_SELECTABLE_COLUMN);
    	non_selectable_column.setDataStoreOnly(true);
    	tree.addComponent(non_selectable_column);
    	tree.setNonSelectableColumn(non_selectable_column);
    	tree.setNodeColumn(NUMBER);
    	tree.setExpansionLevel("full");
    	tree.addComponent(factory.newColumnConfig(TYPE_ICON, true));
        ColumnConfig  number = factory.newColumnConfig ("number","Number", false);
        number.setDataUtilityId("VersionDatautility");
        tree.addComponent(number);
        
        ColumnConfig  name = factory.newColumnConfig ("name","Name", false);
        name.setDataUtilityId("VersionDatautility");
        tree.addComponent(name);
        tree.addComponent(factory.newColumnConfig("oid", true));
        ColumnConfig  qty = factory.newColumnConfig ("qty","Quantity", false);
        qty.setDataUtilityId("VersionDatautility");
        tree.addComponent(qty);
        ColumnConfig  version = factory.newColumnConfig ("Version","VERSION", false);
        version.setDataUtilityId("VersionDatautility");
        tree.addComponent(version);

	    return tree;
     }













  }
